<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="js/jquery-1.8.3.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //1.执行人失去焦点,触发非空验证
            $("[name='executor']").blur(ckexecutor);

            //2.任务描述,失去焦点 触发非空验证
            $("[name='description']").blur(ckdiscription);

            //3.提交按钮点击事件
            $("[value='提交']").click(function () {
                // 获取当前值进行验证
                var executorVal = $("[name='executor']").val();
                var descriptionVal = $("[name='description']").val();

                if(ckexecutor(executorVal) && ckdiscription(descriptionVal)){
                    var executor = $("[name='executor']").val();
                    var description = $("[name='description']").val();
                    var orderlevel = $("[name='orderlevel']").val();
                    var pid = $("#hid").val();

                    $.get("wo/add",
                        {
                            "executor":executor,
                            "description":description,
                            "orderlevel":orderlevel,
                            "pid":pid
                        },
                        function (boo) {
                            JSON.stringify(boo);
                            if(boo){
                                alert("添加成功")
                                window.location.href="woList.jsp";
                            }else {
                                alert("添加失败")
                            }
                        });
                }
            });
        });

        function ckexecutor() {
            var val=$("[name='executor']").val();
            if(val.length==0){
                alert("执行人不能为空");
                return false;
            }
            return true;
        }

        function ckdiscription() {
            var val=$("[name='description']").val();
            if(val.length==0){
                alert("任务描述不能为空");
                return false;
            }
            return true;
        }
    </script>
</head>
<body>
<table>
    <caption>添加工单</caption>
    <tr>
        <td>执行人*</td>
        <td>
            <input type="text" name="executor"/>
        </td>
    </tr>

    <tr>
        <td>任务描述*</td>
        <td>
            <input type="text" name="description"/>
        </td>
    </tr>

    <tr>
        <td>级别*</td>
        <td>
            <select name="orderlevel">
                <option value="1">1级</option>
                <option value="2">2级</option>
                <option value="3">3级</option>
            </select>
        </td>
    </tr>

    <tr>
        <td colspan="2">
            <input type="button" value="提交">
        </td>
    </tr>
    <input type="hidden" id="hid" value="<%=request.getParameter("pid")%>">
</table>
</body>
</html>